/*
 * @(#)ReflectionUtils.java    Jul 7, 2009
 *
 * Copyright 2009 Nyber Shanghai, Inc. All rights reserved.
 */

package com.lab.util;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Class description goes here.
 *
 * @author nickevin@gmail.com
 * @version Jul 7, 2009 3:16:03 PM
 */

public class ReflectionUtils {

	public static <T> List<Method> getGetters(Class<T> clazz) {
		Method[] methods = org.springframework.util.ReflectionUtils.getAllDeclaredMethods(clazz);
		List<Method> list = new ArrayList<Method>();

		for (Method method : methods) {
			String name = method.getName();
			if (name.startsWith("get")) {
				list.add(method);
			}
		}

		list.remove(list.size() - 1);// remove getClass()

		return list;
	}

	public static <T> List<Method> getSetters(Class<T> clazz) {
		Method[] methods = org.springframework.util.ReflectionUtils.getAllDeclaredMethods(clazz);
		List<Method> list = new ArrayList<Method>();

		for (Method method : methods) {
			String name = method.getName();
			if (name.startsWith("set")) {
				list.add(method);
			}
		}

		return list;
	}
}
